package com.zlc.atonce.Util;

import java.util.Objects;

public final class Point {

    public final int x;
    public final int y;
// todo cache points

    private Point(int x, int y) {
        this.x = x;
        this.y = y;
    }

    public static Point of(int x, int y) {
        return new Point(x, y);
    }

    public Point up() {
        return Point.of(x + 1, y);
    }

    public Point down() {
        return Point.of(x - 1, y);
    }

    public Point right() {
        return Point.of(x, y + 1);
    }

    public Point left() {
        return Point.of(x, y - 1);
    }

    public Point add(Point delta) {
        return Point.of(x + delta.getX(), y + delta.getY());
    }

    public boolean inBound(int tlx, int tly, int rbx, int rby) {
        return x >= tlx && y >= tly && x <= rbx && y <= rby;
    }


    public int getX() {
        return x;
    }


    public int getY() {
        return y;
    }


    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Point point = (Point) o;
        return x == point.x && y == point.y;
    }

    @Override
    public int hashCode() {
        return Objects.hash(x, y);
    }

    @Override
    public String toString() {
        return "Point{" +
                "x=" + x +
                ", y=" + y +
                '}';
    }
}
